home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / totsrc.zip / TOTIO3.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-11  |  32KB  |  1,107 lines

  1. {               Copyright 1991 TechnoJock Software, Inc.               }
  2. {                          All Rights Reserved                         }
  3. {                         Restricted by License                        }
  4.  
  5. {                             Build # 1.00                             }
  6.  
  7. Unit totIO3;
  8. {$I TOTFLAGS.INC}
  9.  
  10. {
  11.  Development Notes:
  12.  
  13. }
  14.  
  15. INTERFACE
  16.  
  17. uses DOS, CRT,
  18.      totSYS, totLOOK, totFAST, totSTR, totINPUT, totLINK, totIO1;
  19.  
  20. TYPE
  21.  
  22. pWordwrapIOOBJ = ^WordwrapIOOBJ;
  23. WordwrapIOOBJ = object(MultiLineIOOBJ)
  24.    vTopLine: integer;         {number of first line in window}
  25.    vTotLines: integer;        {total number of lines}
  26.    vListAssigned: boolean;    {is data assigned}
  27.    vScrollBarOn: boolean;     {is the vertical scrollbar required}
  28.    vBoxBorder: boolean;       {is the data enclosed in a box}
  29.    vCursorX: byte;            {position of cursor in Str}
  30.    vCursorY: byte;            {line no. of cursor - from top}
  31.    vMaxLines: integer;        {limit on total number of lines}
  32.    vLineStr: string;          {copy of line being edited}
  33.    vInsert: boolean;          {is field initially in insert mode}
  34.    vWidth: byte;              {maximum width of an input string}
  35.    vEndKey: word;             {key to jump to next field}
  36.    vAllowEdit: boolean;       {can user change the text}
  37.    {methods ...}
  38.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  39.    procedure   WriteLine(OffSet:integer;Status:tStatus);
  40.    procedure   SetEndKey(K:word);
  41.    procedure   SetAllowEdit(On:boolean);
  42.    procedure   DisplayAllLines(Status:tStatus);
  43.    procedure   RefreshScrollBar(Status:tStatus);
  44.    procedure   MoveCursor;
  45.    procedure   CursorJump(Line:integer);
  46.    procedure   CursorUp;
  47.    procedure   CursorDown;
  48.    procedure   CursorLeft;
  49.    procedure   CursorRight;
  50.    procedure   CursorPgUp;
  51.    procedure   CursorPgDn;
  52.    procedure   CursorHome;
  53.    procedure   CursorEnd;
  54.    procedure   CursorTop;
  55.    procedure   CursorBottom;
  56.    procedure   DeleteChar;
  57.    procedure   Backspace;
  58.    procedure   ProcessEnter;
  59.    function    GetNextLinesLeadingSpaces(var StrOne,StrTwo: string;var LastLine: boolean): byte;
  60.    procedure   GetNextLinesFullWords(var StrOne,StrTwo: string;var LastLine: boolean;Line:integer);
  61.    procedure   PushWordsToNextLine(var StrOne,StrTwo: string;var LastLine: boolean;Line:integer);
  62.    procedure   WrapFrom(Line: integer);
  63.    procedure   AdjustMouseKey(var InKey: word;X,Y:byte);
  64.    procedure   MouseChoose(X,Y:byte);
  65.    procedure   ProcessChar(Ch:char);
  66.    procedure   SetIns(InsOn:boolean);
  67.    procedure   WrapFull;                                    VIRTUAL;
  68.    function    Select(K:word; X,Y:byte):tAction;            VIRTUAL;
  69.    function    ProcessKey(InKey:word;X,Y:byte):tAction;     VIRTUAL;
  70.    procedure   Display(Status:tStatus);                     VIRTUAL;
  71.    function    Suspend:boolean;                             VIRTUAL;
  72.    function    GetString(Line:integer): string;             VIRTUAL;
  73.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  74.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  75.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  76.    procedure   InsertAction(InsOn:boolean);                 VIRTUAL;
  77.    destructor  Done;                                        VIRTUAL;
  78. end;
  79.  
  80. pWWArrayIOOBJ = ^WWArrayIOOBJ;
  81. WWArrayIOOBJ = object (WordwrapIOOBJ)
  82.    vArrayPtr: pointer;
  83.    vStrLength: byte;
  84.    {methods ...}
  85.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  86.    procedure   AssignList(var StrArray; Total:Longint; StrLength:byte);
  87.    function    GetString(Line:integer): string;             VIRTUAL;
  88.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  89.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  90.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  91.    destructor  Done;                                        VIRTUAL;
  92. end; {WWArrayIOOBJ}
  93.  
  94. pWWLinkIOOBJ = ^WWLinkIOOBJ;
  95. WWLinkIOOBJ = object (WordwrapIOOBJ)
  96.    vLinkList: ^StrDLLOBJ;
  97.    vWrapping: boolean;
  98.    {methods ...}
  99.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  100.    procedure   AssignList(var LinkList: StrDLLOBJ; Max:integer);
  101.    procedure   WrapFull;                                    VIRTUAL;
  102.    function    GetString(Line:integer): string;             VIRTUAL;
  103.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  104.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  105.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  106.    destructor  Done;                                        VIRTUAL;
  107. end; {WWLinkIOOBJ}
  108.  
  109. procedure IO3Init;
  110.  
  111. IMPLEMENTATION
  112. {||||||||||||||||||||||||||||||||||||||||||||}
  113. {                                            }
  114. {     W W F i e l d O B J   M E T H O D S    }
  115. {                                            }
  116. {||||||||||||||||||||||||||||||||||||||||||||}
  117. constructor WordwrapIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  118. {}
  119. begin
  120.    MultiLineIOOBJ.Init(X1,Y1,width,lines,Title);
  121.    vTopLine := 1;
  122.    vTotLines := 0;
  123.    vListAssigned := false;
  124.    vScrollBarOn := false;
  125.    vCursorX := 1;
  126.    vCursorY := 1;
  127.    vInsert := IOTOT^.InputIns;
  128.    vEndKey := 324; {F10}
  129.    vAllowEdit := true;
  130. end; {WordwrapIOOBJ.Init}
  131.  
  132. procedure WordwrapIOOBJ.SetEndKey(K:word);
  133. {}
  134. begin
  135.    vEndKey := K;
  136. end; {WordwrapIOOBJ.SetEndKey}
  137.  
  138. procedure WordwrapIOOBJ.SetAllowEdit(On:boolean);
  139. {}
  140. begin
  141.    vAllowEdit := On;
  142. end; {WordwrapIOOBJ.SetAllowEdit}
  143.  
  144. procedure WordwrapIOOBJ.WriteLine(OffSet:integer;Status:tStatus);
  145. {}
  146. var 
  147.   Str : string;
  148.   A: byte;
  149. begin
  150.    if vListAssigned then
  151.    begin
  152.       Str := GetString(pred(vTopLine)+OffSet);
  153.       Case Status of
  154.          HiStatus: A := IOTOT^.FieldCol(2);
  155.          Norm: A := IOTOT^.FieldCol(1);
  156.          else A := IOTOT^.FieldCol(4);
  157.       end; {case}
  158.       Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(Offset),A,
  159.                      padleft(Str,vBorder.X2-vBorder.X1,' '));
  160.    end;
  161. end; {WordwrapIOOBJ.WriteLine}
  162.  
  163. procedure WordwrapIOOBJ.DisplayAllLines(Status:tStatus);
  164. {}
  165. var I: integer;
  166. begin
  167.    for I := 1 to vRows do
  168.        WriteLine(I,Status);
  169.    if vCursorX > length(vLineStr) then
  170.       CursorEnd
  171.    else
  172.       MoveCursor;
  173. end; {WordwrapIOOBJ.DisplayAllLines}
  174.  
  175. function WordwrapIOOBJ.Select(K:word; X,Y:byte): tAction;
  176. {}
  177. begin
  178.    vScrollBarOn := (vTotLines > vRows);
  179.    Display(HiStatus);
  180.    WriteMessage;
  181.    MoveCursor;
  182.    Select := none;
  183. end; {WordwrapIOOBJ.Select}
  184.  
  185. procedure WordwrapIOOBJ.MoveCursor;
  186. {}
  187. begin
  188.    Screen.GotoXY(pred(vBorder.X1+vCursorX),pred(vBorder.Y1+vCursorY));
  189. end; {WordwrapIOOBJ.MoveCursor}
  190.  
  191. procedure WordwrapIOOBJ.CursorJump(Line:integer);
  192. {}
  193. var
  194.   Tot: integer;
  195. begin
  196.    Tot := vBorder.Y2 - succ(vBorder.Y1);
  197.    Line := Line - vBorder.Y1;
  198.       if vTotLines <= vRows then  {all Lines on display}
  199.       begin
  200.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  201.          vCursorY := (Line * vTotLines) div Tot;
  202.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  203.          CursorHome;
  204.          MoveCursor;
  205.       end
  206.       else
  207.       begin
  208.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  209.          vTopLine := (Line * vTotLines) div Tot;
  210.          vCursorY := 1;
  211.          vCursorX := 1;
  212.          MoveCursor;
  213.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  214.          DisplayAllLines(HiStatus);
  215.       end;
  216. end; {WordwrapIOOBJ.Cursor}
  217.  
  218. procedure WordwrapIOOBJ.CursorUp;
  219. {}
  220. begin
  221.    if vCursorY = 1 then
  222.    begin
  223.       if vTopLine > 1 then
  224.       begin
  225.          SetString(vTopLine,vLineStr);
  226.          dec(vTopLine);
  227.          vLineStr := GetString(vTopLine);
  228.          DisplayAllLines(HiStatus);
  229.       end;
  230.    end
  231.    else
  232.    begin
  233.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  234.       dec(vCursorY);
  235.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  236.       if vCursorX > length(vLineStr) then
  237.          CursorEnd
  238.       else
  239.          MoveCursor;
  240.    end;
  241. end; {WordwrapIOOBJ.CursorUp}
  242.  
  243. procedure WordwrapIOOBJ.CursorDown;
  244. {}
  245. begin
  246.    if pred(vTopLine) + vCursorY < vTotLines then
  247.    begin
  248.       if vCursorY < vRows then
  249.       begin
  250.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  251.          inc(vCursorY);
  252.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  253.          if vCursorX > length(vLineStr) then
  254.             CursorEnd
  255.          else
  256.             MoveCursor;
  257.       end
  258.       else
  259.       begin
  260.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  261.          inc(vTopLine);
  262.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  263.          DisplayAllLines(HiStatus);
  264.       end;
  265.    end;
  266. end; {WordwrapIOOBJ.CursorDown}
  267.  
  268. procedure WordwrapIOOBJ.CursorLeft;
  269. {}
  270. begin
  271.    if vCursorX > 1 then
  272.    begin
  273.       dec(vCursorX);
  274.       MoveCursor;
  275.    end
  276.    else if (vTopLine > 1) or (vCursorY > 1) then
  277.    begin
  278.       CursorUp;
  279.       CursorEnd;
  280.    end;
  281. end; {WordwrapIOOBJ.CursorLeft}
  282.  
  283. procedure WordwrapIOOBJ.CursorRight;
  284. {}
  285. begin
  286.    if vCursorX <= length(vLineStr) then
  287.    begin
  288.       inc(vCursorX);
  289.       MoveCursor;
  290.    end
  291.    else
  292.    begin
  293.       if pred(vTopLine) + vCursorY < vTotLines then
  294.       begin
  295.          CursorDown;
  296.          CursorHome;
  297.       end;
  298.    end;
  299. end; {WordwrapIOOBJ.CursorRight}
  300.  
  301. procedure WordwrapIOOBJ.CursorPgUp;
  302. {}
  303. begin
  304.    if vTopLine > 1 then
  305.    begin
  306.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  307.       vTopLine := vTopLine - vRows;
  308.       if vTopLine < 1 then
  309.          vTopLine := 1;
  310.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  311.       DisplayAllLines(HiStatus);
  312.    end
  313.    else if vCursorY <> 1 then
  314.    begin
  315.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  316.       vCursorY := 1;
  317.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  318.       MoveCursor;
  319.    end;
  320. end; {WordwrapIOOBJ.CursorPgUp}
  321.  
  322. procedure WordwrapIOOBJ.CursorPgDn;
  323. {}
  324. begin
  325.    if pred(vTopLine + vRows) < vTotLines then
  326.    begin
  327.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  328.       vTopLine := vTopLine + vRows;
  329.       vCursorY := 1;
  330.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  331.       DisplayAllLines(HiStatus);
  332.    end
  333.    else if vCursorY + pred(vTopLine) < vTotLines then
  334.    begin
  335.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  336.       vCursorY := vRows;
  337.       if vCursorY + pred(vTopLine) > vTotLines then
  338.          vCursorY := vTotLines - pred(vTopLine);
  339.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  340.       if vCursorX > length(vLineStr) then
  341.          CursorEnd
  342.       else
  343.          MoveCursor;
  344.    end;
  345. end; {WordwrapIOOBJ.CursorPgDn}
  346.  
  347. procedure WordwrapIOOBJ.CursorHome;
  348. {}
  349. begin
  350.    vCursorX := 1;
  351.    MoveCursor;
  352. end; {WordwrapIOOBJ.CursorHome}
  353.  
  354. procedure WordwrapIOOBJ.CursorEnd;
  355. {}
  356. begin
  357.    vCursorX := succ(length(vLineStr));
  358.    MoveCursor;
  359. end; {WordwrapIOOBJ.CursorEnd}
  360.  
  361. procedure WordwrapIOOBJ.CursorTop;
  362. {}
  363. begin
  364.    if (vCursorY <> 1) or (vTopLine <> 1) then
  365.    begin
  366.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  367.       vCursorY := 1;
  368.       vTopLine := 1;
  369.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  370.       DisplayAllLines(HiStatus);
  371.    end;
  372.    CursorHome;
  373. end; {WordwrapIOOBJ.CursorTop}
  374.  
  375. procedure WordwrapIOOBJ.CursorBottom;
  376. {}
  377. begin
  378.    if vTopLine + pred(vRows) >= vTotLines then
  379.       CursorPgDn
  380.    else
  381.    begin
  382.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  383.       vTopLine := vTotLines - pred(vRows);
  384.       vCursorY := vRows;
  385.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  386.       DisplayAllLines(HiStatus);
  387.    end;
  388. end; {WordwrapIOOBJ.CursorBottom}
  389.  
  390. procedure WordwrapIOOBJ.InsertAction(InsOn:boolean);
  391. {}
  392. begin
  393.    if InsOn then
  394.       Screen.CursHalf
  395.    else
  396.       Screen.CursOn;
  397. end; {WordwrapIOOBJ.ChangeMode}
  398.  
  399. procedure WordwrapIOOBJ.SetIns(InsOn:boolean);
  400. {}
  401. begin
  402.    vInsert := InsOn;
  403. end; {WordwrapIOOBJ.SetIns}
  404.  
  405. procedure WordwrapIOOBJ.DeleteChar;
  406. {}
  407. var I : integer;
  408. begin
  409.   if vLineStr = '' then
  410.   begin
  411.      DeleteLine(pred(vTopLine)+vCursorY);
  412.      vLineStr := GetString(pred(vTopLine)+vCursorY);
  413.      for I := vCursorY to vRows do
  414.         WriteLine(I,HiStatus);
  415.      if vCursorY <> 1 then
  416.      begin
  417.         CursorLeft;
  418.         WrapFrom(Pred(vTopLine) + vCursorY);
  419.      end;
  420.   end
  421.   else
  422.   begin
  423.      delete(vLineStr,vCursorX,1);
  424.      SetString(pred(vTopLine)+vCursorY,vLineStr);
  425.      WrapFrom(Pred(vTopLine) + pred(vCursorY));
  426.   end;
  427. end; {WordwrapIOOBJ.DeleteChar}
  428.  
  429. procedure WordwrapIOOBJ.BackSpace;
  430. {}
  431. begin
  432.    if  not (    (vCursorX = 1)
  433.             and (vCursorY = 1)
  434.             and (vTopLine = 1)
  435.            ) then
  436.    begin
  437.       CursorLeft;
  438.       DeleteChar;
  439.    end;
  440. end; {WordwrapIOOBJ.BackSpace}
  441.  
  442. procedure WordwrapIOOBJ.ProcessEnter;
  443. {splits the line at the cursor, and inserts a blank line}
  444. var
  445.   StrOne, CarryOver: string;
  446.   I : Integer;
  447. begin
  448.   if pred(vTopLine) + vCursorY < pred(vMaxLines) then
  449.   begin
  450.      CarryOver := copy(vLineStr,vCursorX,length(vLineStr)-pred(vCursorX));
  451.      delete(vLineStr,vCursorX,succ(length(vLineStr)-vCursorX));
  452.      SetString(pred(vTopLine)+vCursorY,vLineStr);
  453.      InsertLine(vTopLine+vCursorY);
  454.      if succ(vTopLine + vCursorY) > vTotLines then
  455.         InsertLine(succ(vTopLine+vCursorY));
  456.      if vCursorY + 2 > vRows then
  457.      begin
  458.        if vCursorY = vRows then
  459.           inc(vTopLine,2)
  460.        else
  461.           Inc(vTopLine);
  462.        vCursorY := vRows;
  463.        DisplayAllLines(HiStatus);
  464.      end
  465.      else
  466.      begin
  467.         vCursorY := vCursorY+2;
  468.         for I := 1 to vCursorY do
  469.             WriteLine(I,HiStatus);
  470.      end;
  471.      vCursorX := 1;
  472.      MoveCursor;
  473.      vLineStr := GetString(pred(vTopLine)+vCursorY);
  474.      insert(CarryOver,vLineStr,1);
  475.      WrapFrom(Pred(vTopLine) + vCursorY);
  476.   end;
  477. end; {WordwrapIOOBJ.ProcessEnter}
  478.  
  479. function WordwrapIOOBJ.GetNextLinesLeadingSpaces(var StrOne,StrTwo: string;
  480.                                               var LastLine: boolean): byte;
  481. var Counter : byte;
  482. begin
  483.    counter := 0;
  484.    while (StrTwo <> '')
  485.      and (StrTwo[1] = ' ')
  486.      and (length(StrOne) < vWidth) do
  487.    begin
  488.        StrOne := StrOne + ' ';
  489.        Delete(StrTwo,1,1);
  490.        LastLine := false;
  491.        inc(Counter);
  492.    end;
  493.    GetNextLinesLeadingSpaces := counter;
  494. end; {WordwrapIOOBJ.GetNextLinesLeadingSpaces}
  495.  
  496. procedure WordwrapIOOBJ.GetNextLinesFullWords(var StrOne,StrTwo: string;
  497.                                            var LastLine: boolean; Line: integer);
  498. var
  499.   WordSize: byte;
  500.   RoomLeft: integer;
  501.   Finished: boolean;
  502.   BytesMoved: byte;
  503. begin
  504.    Finished := false;
  505.    BytesMoved := 0;
  506.    repeat
  507.       inc(BytesMoved,GetNextLinesLeadingSpaces(StrOne,StrTwo,LastLine));
  508.       RoomLeft := vWidth - length(StrOne);
  509.       if RoomLeft > 0 then
  510.       begin
  511.          WordSize := pos(' ',StrTwo);
  512.          if WordSize = 0 then
  513.             WordSize := length(StrTwo);
  514.          if (WordSize > 0) and (WordSize <= RoomLeft) then
  515.          begin
  516.              StrOne := StrOne + copy(StrTwo,1,WordSize);
  517.              delete(StrTwo,1,WordSize);
  518.              inc(BytesMoved,WordSize);
  519.              if StrTwo = '' then  {shift up the next line}
  520.              begin
  521.                 DeleteLine(succ(Line));
  522.                 StrTwo := GetString(Succ(Line));
  523.              end;
  524.              if StrTwo = '' then
  525.                 LastLine := true
  526.              else
  527.                 LastLine := false;
  528.          end
  529.          else
  530.             Finished := true;
  531.       end
  532.       else
  533.          Finished := true;
  534.    until Finished;
  535.    if (BytesMoved > 0) and (succ(Line) = pred(vTopLine) + vCursorY) then {move cursor}
  536.    begin
  537.       if vCursorX > BytesMoved then
  538.          dec(vCursorX,BytesMoved)
  539.       else
  540.       begin
  541.          CursorUp;
  542.          vCursorX := length(StrOne) - pred(BytesMoved);
  543.       end;
  544.       MoveCursor;
  545.    end;
  546. end; {WordwrapIOOBJ.GetNextLinesFullWords}
  547.  
  548. procedure WordwrapIOOBJ.PushWordsToNextLine(var StrOne,StrTwo: string;
  549.                                          var LastLine: boolean;Line:integer);
  550. {}
  551. var Counter : integer;
  552. begin
  553.    Counter := length(StrOne);
  554.    repeat
  555.       dec(Counter);
  556.    until (Counter = 0) or ((StrOne[Counter] = ' ') and (Counter <= vWidth));
  557.    {check for STRTWO = ''}
  558.    if StrTwo = '' then {insert a new line}
  559.    begin
  560.       InsertLine(succ(Line));
  561.    end;
  562.    if (Counter = 0) and (length(StrOne)>vWidth) then {no spaces so split word}
  563.       Counter := vWidth;
  564.    insert(copy(StrOne,succ(Counter),length(StrOne)-Counter),StrTwo,1);
  565.    delete(StrOne,succ(Counter),length(StrOne)-Counter);
  566.    if length(StrTwo) > vWidth then
  567.       Lastline := false;
  568. end; {WordwrapIOOBJ.PushWordsToNextLine}
  569.  
  570. procedure WordwrapIOOBJ.WrapFrom(Line:integer);
  571. {}
  572. var
  573.   StrOne,StrTwo: string;
  574.   LastLine: boolean;
  575.   I : integer;
  576. begin
  577.    if Line < 1 then
  578.       Line := 1;
  579.    if Line >= vMaxLines then {nowhere to wrap!}
  580.    begin
  581.       if Line = pred(vTopLine) + vCursorY then
  582.       begin
  583.          if length(vLineStr) > vWidth then
  584.             vLineStr := copy(vLineStr,1,vWidth);
  585.          SetString(vCursorY,vLineStr);
  586.          WriteLine(vCursorY,HiStatus);
  587.       end;
  588.    end
  589.    else
  590.    begin
  591.       if Line = pred(vTopLine) + vCursorY then  {active line}
  592.          StrOne := vLineStr
  593.       else
  594.          StrOne := GetString(Line);
  595.       if succ(Line) =pred(vTopLine) + vCursorY then
  596.          StrTwo := vLineStr
  597.       else
  598.          StrTwo := GetString(succ(Line));
  599.       repeat
  600.          LastLine:= true;
  601.          if length(StrOne) > vWidth then   {line must be truncated}
  602.          begin
  603.             PushWordsToNextLine(StrOne,StrTwo,LastLine,Line);
  604.             SetString(Line,StrOne);
  605.             if not LastLine then
  606.             begin
  607.                Inc(Line);
  608.                StrOne := StrTwo;
  609.                if succ(Line) = pred(vTopLine) + vCursorY then
  610.                   StrTwo := vLineStr
  611.                else
  612.                   StrTwo := GetString(succ(Line));
  613.             end
  614.             else
  615.                SetString(succ(Line),StrTwo);
  616.          end
  617.          else                             {line might be expanded}
  618.          begin
  619.             if StrTwo = '' then
  620.             begin
  621.                Lastline := true;
  622.                SetString(Line,StrOne);
  623.             end
  624.             else
  625.             begin
  626.                LastLine := false;
  627.                if StrOne <> '' then
  628.                   GetNextLinesFullWords(StrOne,StrTwo,LastLine,Line);
  629.               (*
  630.                SetString(Line,StrOne);
  631.                SetString(succ(Line),StrTwo);
  632.                if not LastLine then
  633.                begin
  634.                   Inc(Line);
  635.                   StrOne := StrTwo;
  636.                   StrTwo := GetString(succ(Line));
  637.                end;
  638.                *)
  639.                SetString(Line,StrOne);
  640.                if not LastLine then
  641.                begin
  642.                   Inc(Line);
  643.                   StrOne := StrTwo;
  644.                   StrTwo := GetString(succ(Line));
  645.                end
  646.                else
  647.                   SetString(succ(Line),StrTwo);
  648.             end;
  649.          end;
  650.       Until LastLine;
  651.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  652.       if (vCursorY > 1) and (Line >= vTopLine) then
  653.          WriteLine(pred(vCursorY),HiStatus);
  654.       for I := vCursorY to vRows do
  655.          WriteLine(I,HiStatus)
  656.    end;
  657. end; {WordwrapIOOBJ.WrapFrom}
  658.  
  659. procedure WordwrapIOOBJ.WrapFull;
  660. {Call this method to word wrap an object before displaying it. This saves
  661.  you the chore of inititally wordwrapping the default text.}
  662. var
  663.   StrOne,StrTwo: string;
  664.   LastLine: boolean;   {no used but must be passed to other methods}
  665.   Line : integer;
  666. begin
  667.    if vListAssigned then
  668.    begin
  669.       Line := 1;
  670.       LastLine := false;
  671.       StrOne := GetString(1);
  672.       StrTwo := GetString(2);
  673.       repeat
  674.           if length(StrOne) > vWidth then
  675.             PushWordsToNextLine(StrOne,StrTwo,LastLine,Line)
  676.           else
  677.              if StrOne <> '' then
  678.                 GetNextLinesFullWords(StrOne,StrTwo,LastLine,Line);
  679.           SetString(Line,StrOne);
  680.           Inc(Line);
  681.           if Line <= vMaxLines then
  682.           begin
  683.              StrOne := StrTwo;
  684.              StrTwo := GetString(succ(Line));
  685.           end;
  686.       until Line = vMaxLines;
  687.       SetString(Line,copy(StrOne,1,vWidth));
  688.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  689.    end;
  690. end;  {WordwrapIOOBJ.WrapFull}
  691.  
  692. procedure WordwrapIOOBJ.ProcessChar(Ch:char);
  693. {}
  694. var
  695.   NewX : byte;
  696.   Finished : boolean;
  697. begin
  698.    if not ((vCursorX > vWidth) and (vCursorY + pred(vTopLine) = vMaxLines)) then
  699.    if vInsert then
  700.    begin
  701.       Insert(Ch,vLineStr,vCursorX);
  702.       if  (Ch = ' ')
  703.       and (pos(' ',vLineStr) = vCursorX)
  704.       and (vCursorY <> 1) then {just entered first space on line}
  705.       begin
  706.          CursorRight;
  707.          Wrapfrom(pred(vTopLine)+pred(vCursorY));
  708.       end
  709.       else
  710.       begin
  711.          if length(vLineStr) > vWidth then
  712.          begin
  713.             WrapFrom(pred(vTopLine)+vCursorY);
  714.             if vCursorX > length(vLineStr) then
  715.             begin
  716.                NewX := vCursorX - pred(length(vLineStr));
  717.                CursorHome;
  718.                CursorDown;
  719.                vCursorX := NewX;
  720.                MoveCursor;
  721.             end
  722.             else
  723.                CursorRight;
  724.          end
  725.          else
  726.          begin
  727.             Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(vCursorY),
  728.                            IOTOT^.FieldCol(2),
  729.                            padleft(vLineStr,vWidth,' '));
  730.             CursorRight;
  731.          end;
  732.       end;
  733.    end
  734.    else  {overtype mode}
  735.    begin
  736.          if vLineStr = '' then
  737.              vLineStr := Ch
  738.          else if (vCursorX <= length(vLineStr)) then
  739.             vLineStr[vCursorX] := Ch
  740.          else
  741.             vLineStr := vLineStr + Ch;
  742.       if  ((Ch = ' ')
  743.            and (pos(' ',vLineStr) = vCursorX)
  744.            and (vCursorY <> 1))
  745.       or (vCursorX > vWidth) then {just entered first space on line}
  746.       begin
  747.          Wrapfrom(pred(vTopLine)+pred(vCursorY));
  748.          if vCursorX > length(vLineStr) then
  749.          begin
  750.             NewX := vCursorX - pred(length(vLineStr));
  751.             CursorHome;
  752.             CursorDown;
  753.             vCursorX := NewX;
  754.             MoveCursor;
  755.          end
  756.          else
  757.             CursorRight;
  758.       end
  759.       else
  760.       begin
  761.          Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(vCursorY),IOTOT^.FieldCol(2),
  762.                         padleft(vLineStr,vBorder.X2-vBorder.X1,' '));
  763.          CursorRight;
  764.       end;
  765.    end;
  766. end;  {WordwrapIOOBJ.ProcessChar}
  767.  
  768. procedure WordwrapIOOBJ.AdjustMouseKey(var InKey: word;X,Y:byte);
  769. {}
  770. begin
  771.    if (X = vBorder.X2) and (vScrollBarOn) then {probably on scroll bar}
  772.    begin
  773.       if Y = vBorder.Y2 then
  774.          InKey := 611
  775.       else if Y = vBorder.Y1 then
  776.          InKey := 610
  777.       else if (Y > vBorder.Y1) and (Y < vBorder.Y2) then
  778.          Inkey := 614;
  779.    end;
  780. end; {WordwrapIOOBJ.AdjustMouseKey}
  781.  
  782. procedure WordwrapIOOBJ.MouseChoose(X,Y:byte);
  783. {moves cursor to hit location}
  784. begin
  785.    if (X >= vBorder.X1)
  786.    and (X < vBorder.X2 - ord(not vScrollBarOn))
  787.    and (Y >= vBorder.Y1)
  788.    and (Y <= vBorder.Y2) then
  789.    begin
  790.       vCursorX := X - pred(vBorder.X1);
  791.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  792.       vCursorY := Y - pred(vBorder.Y1);
  793.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  794.       if vCursorX > length(vLineStr) then
  795.          CursorEnd;
  796.       MoveCursor;
  797.    end;
  798. end; {WordwrapIOOBJ.MouseChoose}
  799.  
  800. function WordwrapIOOBJ.ProcessKey(InKey:word;X,Y:byte): tAction;
  801. {}
  802. begin
  803.    if InKey = 513 then
  804.       AdjustMousekey(Inkey,X,Y);
  805.    case InKey of
  806.       610,328: CursorUp;
  807.       611,336: CursorDown;
  808.       513: MouseChoose(X,Y);
  809.       337: CursorPgDn;
  810.       329: CursorPgUp;
  811.       335: CursorEnd;
  812.       327: CursorHome;
  813.       388: CursorTop;     {^PgUp}
  814.       374: CursorBottom;  {^PgDn}
  815.       333: CursorRight;
  816.       331: CursorLeft;
  817.       614: begin          {vertical scroll bar}
  818.               if Y = succ(vBorder.Y1) then
  819.                  CursorTop
  820.               else if Y = pred(vBorder.Y2) then
  821.                  CursorBottom
  822.               else
  823.                  CursorJump(Y); {vertical scroll bar}
  824.            end;
  825.       else if vAllowEdit then
  826.          case InKey of
  827.             8:       BackSpace;
  828.             339:     DeleteChar;
  829.             338: begin
  830.                     vInsert := not vInsert;
  831.                     if  (vCursorX > 1)
  832.                     and (vCursorX > length(vLineStr))
  833.                     and not vInsert then {cannot be past end in overtype mode}
  834.                        CursorLeft;
  835.                     InsertAction(vInsert);
  836.                  end;
  837.             13: ProcessEnter;
  838.             32..255: ProcessChar(chr(InKey));    {characters}
  839.          end; {sub case}
  840.    end; {case}
  841.    vScrollBarOn := (vTotLines > vRows);
  842.    RefreshScrollBar(HiStatus);
  843.    if InKey = vEndKey then
  844.       Processkey := NextField
  845.    else
  846.       ProcessKey := None;
  847. end; {WordwrapIOOBJ.ProcessKey}
  848.  
  849. procedure WordwrapIOOBJ.RefreshScrollBar(Status:tStatus);
  850. {}
  851. var Col:byte;
  852. begin
  853.    Case Status of
  854.       HiStatus: Col := IOTOT^.FieldCol(2);
  855.       Norm: Col := IOTOT^.FieldCol(1);
  856.       else Col := IOTOT^.FieldCol(4);
  857.    end; {case}
  858.    with vBorder do
  859.    if vScrollBarOn then
  860.       Screen.WriteVScrollBar(X2,Y1,Y2,Col,pred(vTopLine+vCursorY),vTotLines)
  861.    else
  862.       Screen.WriteVert(X2,Y1,Col,replicate(succ(Y2-Y1),' '));
  863. end; {WordwrapIOOBJ.RefreshScrollBar}
  864.  
  865. procedure WordwrapIOOBJ.Display(Status:tStatus);
  866. {}
  867. var I : integer;
  868. begin
  869.    MultiLineIOOBJ.Display(Status);
  870.    for I := 1 to vRows do
  871.       WriteLine(I,Status);
  872.    RefreshScrollBar(Status);
  873. end; {WordwrapIOOBJ.Display}
  874.  
  875. function WordwrapIOOBJ.Suspend:boolean;
  876. {}
  877. begin
  878.    vScrollBarOn := false;
  879.    SetString(pred(vTopLine)+vCursorY,vLineStr);
  880.    Suspend := VisibleIOOBJ.Suspend;
  881. end; {WordwrapIOOBJ.Suspend}
  882.  
  883. function WordwrapIOOBJ.GetString(Line:integer): string;
  884. {abstract}
  885. begin end;
  886.  
  887. procedure WordwrapIOOBJ.SetString(Line:integer;Str: string);
  888. {abstract}
  889. begin end;
  890.  
  891. procedure WordwrapIOOBJ.DeleteLine(Line:integer);
  892. {abstract}
  893. begin end;
  894.  
  895. procedure WordwrapIOOBJ.InsertLine(Line:integer);
  896. {abstract}
  897. begin end;
  898.  
  899. destructor WordwrapIOOBJ.Done;
  900. {}
  901. begin
  902.    MultiLineIOOBJ.Done;
  903. end; {WordwrapIOOBJ.Done}
  904. {||||||||||||||||||||||||||||||||||||||||||||}
  905. {                                            }
  906. {     W W A r r a y O B J   M E T H O D S    }
  907. {                                            }
  908. {||||||||||||||||||||||||||||||||||||||||||||}
  909. constructor WWArrayIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  910. {}
  911. begin
  912.    WordwrapIOOBJ.Init(X1,Y1,width,lines,Title);
  913. end; {WWArrayIOOBJ.Init}
  914.  
  915. procedure WWArrayIOOBJ.AssignList(var StrArray; Total:Longint; StrLength:byte);
  916. {}
  917. begin
  918.    vArrayPtr := @StrArray;
  919.    vStrLength := StrLength;
  920.    vWidth := StrLength;
  921.    vMaxLines := Total;
  922.    vTotLines := Total;
  923.    vListAssigned := true;
  924.    vLineStr := GetString(1);
  925. end; {WWArrayIOOBJ.AssignList}
  926.  
  927. function WWArrayIOOBJ.GetString(Line:integer): string;
  928. {}
  929. var
  930.   W : word;
  931.   TempStr : String;
  932.   ArrayOffset: word;
  933. begin
  934.    if (Line > 0) and (Line <= vTotLines) then
  935.    begin
  936.       W := pred(Line) * succ(vStrLength);
  937.       ArrayOffset := Ofs(vArrayPtr^) + W;
  938.       Move(Mem[Seg(vArrayPtr^):ArrayOffset],TempStr,1);
  939.       Move(Mem[Seg(vArrayPtr^):succ(ArrayOffset)],TempStr[1],ord(TempStr[0]));
  940.    end
  941.    else
  942.       TempStr := '';
  943.    GetString := TempStr;
  944. end; {WWArrayIOOBJ.GetString}
  945.  
  946. procedure WWArrayIOOBJ.SetString(Line:integer;Str: string);
  947. {}
  948. var
  949.   W : word;
  950.   ArrayOffset: word;
  951. begin
  952.    if (Line > 0) and (Line <= vTotLines) then
  953.    begin
  954.       W := pred(Line) * succ(vStrLength);
  955.       ArrayOffset := Ofs(vArrayPtr^) + W;
  956.       Move(Str[0],Mem[Seg(vArrayPtr^):ArrayOffset],succ(length(Str)));
  957.    end;
  958. end; {WWArrayIOOBJ.SetString}
  959.  
  960. procedure WWArrayIOOBJ.DeleteLine(Line:integer);
  961. {}
  962. var
  963.   Null : char;
  964.   W : word;
  965.   ArrayOffset: word;
  966. begin
  967.    if (Line > 0) and (Line <= vTotLines) then
  968.    begin
  969.       W := pred(Line) * succ(vStrLength);
  970.       ArrayOffset := Ofs(vArrayPtr^) + W;
  971.       Move(Mem[Seg(vArrayPtr^):ArrayOffset+succ(vStrLength)],
  972.            Mem[Seg(vArrayPtr^):ArrayOffset],
  973.            (vTotLines - Line)*succ(vStrlength));
  974.       {empty last line}
  975.       W := pred(vTotLines) * succ(vStrLength);
  976.       ArrayOffset := Ofs(vArrayPtr^) + W;
  977.       Null := char(0);
  978.       Move(Null,Mem[Seg(vArrayPtr^):ArrayOffset],1);
  979.    end;
  980. end; {WWArrayIOOBJ.DeleteLine}
  981.  
  982. procedure WWArrayIOOBJ.InsertLine(Line:integer);
  983. {}
  984. var
  985.   Null : char;
  986.   W : word;
  987.   ArrayOffset: word;
  988. begin
  989.    if (Line > 0) and (Line <= vTotLines) then
  990.    begin
  991.       W := pred(Line) * succ(vStrLength);
  992.       ArrayOffset := Ofs(vArrayPtr^) + W;
  993.       Move(Mem[Seg(vArrayPtr^):ArrayOffset],
  994.            Mem[Seg(vArrayPtr^):ArrayOffset+succ(vStrLength)],
  995.            (vTotLines - Line)*succ(vStrlength));
  996.       {empty new line}
  997.       Null := char(0);
  998.       Move(Null,Mem[Seg(vArrayPtr^):ArrayOffset],1);
  999.    end;
  1000. end; {WWArrayIOOBJ.InsertLine}
  1001.  
  1002. destructor WWArrayIOOBJ.Done;
  1003. {}
  1004. begin
  1005.    WordwrapIOOBJ.Done;
  1006. end; {WWArrayIOOBJ.Done}
  1007. {||||||||||||||||||||||||||||||||||||||||||}
  1008. {                                          }
  1009. {     W W L i n k O B J   M E T H O D S    }
  1010. {                                          }
  1011. {||||||||||||||||||||||||||||||||||||||||||}
  1012. constructor WWLinkIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  1013. {}
  1014. begin
  1015.    WordwrapIOOBJ.Init(X1,Y1,width,lines,Title);
  1016.    vWidth := pred(vBorder.X2 - vBorder.X1);
  1017.    vWrapping := false;
  1018. end; {WWLinkIOOBJ.Init}
  1019.  
  1020. procedure WWLinkIOOBJ.AssignList(var LinkList:StrDLLOBJ; Max:integer);
  1021. {}
  1022. begin
  1023.    vLinkList := @LinkList;
  1024.    vMaxLines := Max;
  1025.    vTotLines := LinkList.TotalNodes;
  1026.    vListAssigned := true;
  1027.    vLineStr := GetString(1);
  1028.    vScrollBarOn := (vTotLines > vRows);
  1029. end; {WWLinkIOOBJ.AssignList}
  1030.  
  1031. function WWLinkIOOBJ.GetString(Line:integer): string;
  1032. {}
  1033. var
  1034.   TempPtr : DLLNodePtr;
  1035. begin
  1036.    TempPtr := vLinkList^.NodePtr(Line);
  1037.    if TempPtr <> Nil then
  1038.       vLinkList^.ShiftActiveNode(TempPtr,Line);
  1039.    if vWrapping then
  1040.       GetString := vLinkList^.GetStr(TempPtr,1,255)
  1041.    else
  1042.       GetString := vLinkList^.GetStr(TempPtr,1,vWidth)
  1043. end; {WWLinkIOOBJ.GetString}
  1044.  
  1045. procedure WWLinkIOOBJ.SetString(Line:integer;Str: string);
  1046. {}
  1047. var
  1048.   Ecode: integer;
  1049. begin
  1050.    ECode := vLinkList^.Change(vLinkList^.NodePtr(Line),Str);
  1051. end; {WWLinkIOOBJ.SetString}
  1052.  
  1053. procedure WWLinkIOOBJ.DeleteLine(Line:integer);
  1054. {}
  1055. begin
  1056.    vLinkList^.DelNode(vLinkList^.NodePtr(Line));
  1057.    dec(vTotLines);
  1058. end; {WWLinkIOOBJ.DeleteLine}
  1059.  
  1060. procedure WWLinkIOOBJ.InsertLine(Line:integer);
  1061. {}
  1062. var
  1063.   Null: string;
  1064.   ECode: integer;
  1065. begin
  1066.    Null := '';
  1067.    Ecode := vLinkList^.InsertBefore(vLinkList^.NodePtr(Line),Null);
  1068.    if Ecode = 3 then {add a new line to end of list}
  1069.       Ecode := vLinkList^.Add(Null);
  1070.    vTotLines := vLinkList^.TotalNodes;
  1071. end; {WWLinkIOOBJ.InsertLine}
  1072.  
  1073. procedure WWLinkIOOBJ.WrapFull;
  1074. {}
  1075. begin
  1076.    vWrapping := true;
  1077.    WordwrapIOOBJ.WrapFull;
  1078.    with vLinkList^ do
  1079.       ShiftActiveNode(EndNodePtr,TotalNodes);
  1080.    vWrapping := false;
  1081.    vTotLines := vLinkList^.TotalNodes;
  1082.    vScrollBarOn := (vTotLines > vRows);
  1083. end; {WWLinkIOOBJ.WrapFull}
  1084.  
  1085. destructor WWLinkIOOBJ.Done;
  1086. {}
  1087. begin
  1088.    WordwrapIOOBJ.Done;
  1089. end; {WWLinkIOOBJ.Done}
  1090. {|||||||||||||||||||||||||||||||||||||||||||||||}
  1091. {                                               }
  1092. {     U N I T   I N I T I A L I Z A T I O N     }
  1093. {                                               }
  1094. {|||||||||||||||||||||||||||||||||||||||||||||||}
  1095. procedure IO3Init;
  1096. {initilizes objects and global variables}
  1097. begin
  1098.  
  1099. end; {IO3Init}
  1100.  
  1101. {end of unit - add initialization routines below}
  1102. {$IFNDEF OVERLAY}
  1103. begin
  1104.    IO3Init;
  1105. {$ENDIF}
  1106. end.
  1107.